package com.jic.market.controller.manage;

import com.jic.common.base.vo.RestResult;
import com.jic.market.api.manage.PromotionMerchantApi;
import com.jic.market.common.util.JsonUtil;
import com.jic.market.request.PromotionMerchantRequest;
import com.jic.market.request.PromotionMerchantRequestList;
import com.jic.market.request.PromotionRequest;
import com.jic.market.request.manager.base.PromotionMerchantAndStoreIsNullRequest;
import com.jic.market.response.PageResponse;
import com.jic.market.response.PromotionMerchantResponse;
import com.jic.market.service.PromotionMerchantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;


/**
 * 商家、店铺
 *
 * @author guohuayong
 * @date: 2020年01月10日
 */
@RestController
@RequestMapping("/promotionMerchant")
public class PromotionMerchantController implements PromotionMerchantApi {

    @Autowired
    PromotionMerchantService promotionMerchantService;

    @PostMapping("/merchantAndStoreIsNull")
    @Override
    public RestResult<Boolean> merchantAndStoreIsNull(@RequestBody PromotionMerchantAndStoreIsNullRequest request) {
        return promotionMerchantService.merchantAndStoreIsNull(request);
    }


    @PostMapping("/listByPage")
    @Override
    public RestResult<PageResponse<PromotionMerchantResponse>> list(@RequestBody PromotionMerchantRequest request) {
        PageResponse<PromotionMerchantResponse> entityList = promotionMerchantService.listByPage(request);
        return RestResult.success(entityList);
    }

    @Override
    public RestResult<PromotionMerchantResponse> detail(HttpServletRequest servletRequest, PromotionRequest request) {
        return null;
    }


    @PostMapping("/deleteByPromotionId")
    @Override
    public RestResult<Integer> deleteByPromotionId(@RequestBody PromotionMerchantRequest pomotion) {

        Integer ret = promotionMerchantService.deleteByPromotionId(pomotion);

        return RestResult.success(ret);
    }


    @PostMapping("/deleteById")
    @Override
    public RestResult<Integer> deleteById(@RequestBody PromotionMerchantRequest pomotion) {

        Integer ret = promotionMerchantService.deleteById(pomotion.getId());

        return RestResult.success(ret);
    }




    @PostMapping("/saveBatch")
    @Override
    public RestResult<Integer> saveBatchByPromotionId(@RequestBody PromotionMerchantRequestList pomotionListObject) {


        Integer ret = promotionMerchantService.saveBatchByPromotionId(pomotionListObject.getPomotionList());
        return RestResult.success(ret);
    }

    public static void main(String[] args) {
        PromotionMerchantRequest p = new PromotionMerchantRequest();
        p.setId(0L);
        p.setPromotionId(0L);
        p.setMerchantId(0L);
        p.setMerchantType(0);
        p.setMerchantName("");
        p.setStoreId(0L);
        p.setCreateTime(new Date());
        p.setCreator(0L);
        p.setCreatorName("");
        p.setUpdateTime(new Date());
        p.setUpdator(0L);
        p.setUpdatorName("");


        String s = JsonUtil.toJson(p);
        System.out.println(s);
    }


}
